from Test import *
from Xm import *
+from config import *
class NetworkError(Exception):
def __init__(self, msg):
def undo_dom0_alias(eth, ip):
traceCommand("ip addr del " + ip + " dev " + eth)
+def net_from_ip(ip):
+ return ip[:ip.rfind(".")] + ".0/24"
+
class XmNetwork:
def __init__(self):
domnum = int(dom[len("dom"):])
return "169.254."+ str(ethnum+153) + "." + str(domnum+10)
- def ip(self, dom, interface, todomname=None, toeth=None):
+ def ip(self, dom, interface, todomname=None, toeth=None, bridge=None):
newip = self.calc_ip_address(dom, interface)
# If the testcase is going to talk to dom0, we need to add an
# IP address in the proper subnet
if dom == "dom0":
- # The domain's vif is a convenient place to add to
- vifname = "vif" + str(domid(todomname)) + "." + toeth[3:]
+ if ENABLE_HVM_SUPPORT:
+ # HVM uses ioemu which uses a bridge
+ if not bridge:
+ SKIP("no bridge supplied")
+ else:
+ vifname = bridge
+ else:
+ # The domain's vif is a convenient place to add to
+ vifname = "vif" + str(domid(todomname)) + "." + toeth[3:]
# register the exit handler FIRST, just in case
atexit.register(undo_dom0_alias, vifname, newip)
" dev " + vifname)
if status:
SKIP("\"ip addr add\" failed")
+
+ if ENABLE_HVM_SUPPORT:
+ # We need to add a route to the bridge device
+ network = net_from_ip(newip)
+ status, output = traceCommand("ip route add " + network + " dev " + vifname + " scope link")
+
+ if status:
+ SKIP("\"ip route add\" failed")
+
return newip
def mask(self, dom, interface):
FAIL(str(e))
# Fire up a guest domain w/1 nic
-config = {"vif" : ["ip=%s" % ip]}
+if ENABLE_HVM_SUPPORT:
+ brg = "xenbr0"
+ config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
+else:
+ config = {"vif" : ['ip=%s' % ip ]}
+ brg = None
+
domain = XmTestDomain(extraConfig=config)
try:
domain.start()
try:
# Add a suitable dom0 IP address
- dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0")
+ dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0", bridge=brg)
except NetworkError, e:
FAIL(str(e))